<?php

/**
 * ticketNote actions.
 *
 * @package	FBS
 * @subpackage ticketNote
 * @author	 Your name here
 * @version	SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 * @property TicketForm $form
 * @property TicketNote $ticket_note
 */
class ticketNoteActions extends sfActions {

	/**
	 * @param sfWebRequest $request
	 * @return void
	 */
	public function executeIndex(sfWebRequest $request) {
		$this->forward404();
	}

	/**
	 * @param sfWebRequest $request
	 * @return void
	 */
	public function executeShow(sfWebRequest $request) {
		$this->ticket_note = Doctrine_Core::getTable('TicketNote')->find(array( $request->getParameter('id') ));
		$this->forward404Unless((bool)$this->ticket_note);
		$this->redirect('ticket/show/id/'.$this->ticket_note->getTicketId());
	}

	/**
	 * @param sfWebRequest $request
	 * @return void
	 */
	public function executeNew(sfWebRequest $request) {
		$this->form = new TicketNoteForm();
	}

	/**
	 * @param sfWebRequest $request
	 * @return void
	 */
	public function executeCreate(sfWebRequest $request) {
		$this->forward404Unless($request->isMethod(sfRequest::POST));

		$this->form = new TicketNoteForm();
		$this->processForm($request, $this->form);

		$this->setTemplate('new');
	}

	/**
	 * @param sfWebRequest $request
	 * @return void
	 */
	public function executeEdit(sfWebRequest $request) {
		$this->forward404Unless($ticket_note = Doctrine_Core::getTable('TicketNote')->find(array( $request->getParameter('id') )), sprintf('Object ticket_note does not exist (%s).', $request->getParameter('id')));
		$this->form = new TicketNoteForm($ticket_note);
	}

	/**
	 * @param sfWebRequest $request
	 * @return void
	 */
	public function executeUpdate(sfWebRequest $request) {
		$this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
		$this->forward404Unless($ticket_note = Doctrine_Core::getTable('TicketNote')->find(array( $request->getParameter('id') )), sprintf('Object ticket_note does not exist (%s).', $request->getParameter('id')));
		$this->form = new TicketNoteForm($ticket_note);

		$this->processForm($request, $this->form);

		$this->setTemplate('edit');
	}

	/**
	 * @param sfWebRequest $request
	 * @return void
	 */
	public function executeDelete(sfWebRequest $request) {
		$request->checkCSRFProtection();

		$this->forward404Unless($ticket_note = Doctrine_Core::getTable('TicketNote')->find(array( $request->getParameter('id') )), sprintf('Object ticket_note does not exist (%s).', $request->getParameter('id')));
		$ticket_note->delete();

		$this->redirect('ticketNote/index');
	}

	/**
	 * @param sfWebRequest $request
	 * @param sfForm $form
	 * @return void
	 */
	protected function processForm(sfWebRequest $request, sfForm $form) {
		$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
		if ($form->isValid()) {
			$ticket_note = $form->save();

			$this->redirect('ticketNote/edit?id=' . $ticket_note->getId());
		}
	}
}
